package com.fh.service.runbatch;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fh.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.fh.dao.DaoSupport;
import com.fh.mapper.loan.CallLoanInfoMapper;
import com.fh.mapper.loan.MidCallLoanInfoMapper;
import com.fh.mapper.loan.RunBatchFlagMapper;
import com.fh.model.loan.CallLoanInfo;
import com.fh.model.loan.MidCallLoanInfo;
import com.fh.model.loan.RunBatchFlag;
import com.fh.model.loan.TransferHistoryInfo;
import com.fh.model.system.Organization;
import com.fh.service.system.organization.OrganizationServiceImpl;

/**
 * 跑批
 *
 * @author yc、
 *
 */
@Service
public class RunBatchServiceImpl implements IRunBatchService{

	private Logger loger = LoggerFactory.getLogger(RunBatchServiceImpl.class);

	@Autowired
	private CallLoanInfoMapper mapper;
	@Value("${url.cashURL}")
	private String cashURL;
	@Value("${url.adminURL}")
	private String adminURL;
	@Autowired
	private MidCallLoanInfoMapper midCallLoanInfoMapper;
	@Autowired
	private OrganizationServiceImpl organizationService;
	@Autowired
	private DaoSupport dao;
	@Autowired
	private RunBatchFlagMapper runBatchFlagMapper;

	/**
	 * 通过还款订单号查询是否存在该案件(并且状态不为已结案)
	 *
	 */
	@Transactional(readOnly=true)
	public CallLoanInfo selectByRepaymentId(String repaymentId) {
		return mapper.selectByRepaymentId(repaymentId);
	}

	/**
	 * 插入跑批数据
	 *
	 */
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public void insert(CallLoanInfo info) {
		int a = mapper.insert(info);
		if (a <= 0){
            throw new RuntimeException(info.getRepaymentId() + "插入失败!");
        }
	}
	/**
	 * 跑批更新逾期数据
	 */
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public void update(CallLoanInfo info) {
		int count = mapper.update(info);
		if (count <= 0) {
			throw new RuntimeException("乐观锁失败!");
		}
	}

	//获取所有的借款产品的类型(今日现金  + 信用卡贷 + 融360 + 消费分期 + 游戏贷)
	@SuppressWarnings("all")
	public List<Map<String, Object>> getProductName(){
		Map<String, String> parameters = new HashMap<String, String>();
	    List<Map<String,Object>> maps = new ArrayList<Map<String,Object>>();
	    String result = null;
	    EhcacheUtil ehcacheUtil = EhcacheUtil.getInstance();//缓存对象
	    if (ehcacheUtil.get("paopi", "paopiProductName") == null) {
	    	 result =HttpUtils.sendPost(adminURL+ "/api/loanProducts2", parameters);
	    	 loger.info("获取标的库里面的产品信息==={}", result);
	    	 ehcacheUtil.put("paopi", "paopiProductName", result);
		}else{
			result = String.valueOf(ehcacheUtil.get("paopi", "paopiProductName"));
			 ehcacheUtil.put("paopi", "paopiProductName", result);
		}
		Map map = new HashMap();
        map= JsonUtil.jsonToMap(result);
        if(0==(int)map.get("code")){
    	   maps =(List<Map<String, Object>>)map.get("list");//获取所有的查询数据
        }else{
    	   loger.error("获取标的后台接口错误=====>{}" + result);
        }
	    return maps;
	}

	/**
	 * 分页获取总数据量
	 *
	 */
	@Transactional(readOnly=true)
    public List<MidCallLoanInfo> selectMidCallLoanInfo(int beginIndex, int pageSize){
	    return midCallLoanInfoMapper.selectAll(beginIndex,pageSize);
    }
	/**
	 * 单期产品(现金贷 + 融360 + 游戏贷)
	 *
	 * @param m 跑批中间表
	 * @param info	跑批总案件表
	 * @param productInfo 分装产品来源对象
	 * @param productSource 产品来源
	 */
	public void singleProduct(MidCallLoanInfo m,CallLoanInfo info, ProductInfo productInfo,String productSource){
		 //循环迭代获取对应的产品
		 List<Map<String,Object>> product = new ArrayList<>();
		 if (productSource.equals(Const.JRXJ_PRODUCT)) {
			 //今日现金产品
			 product = productInfo.getJRXJProduct();
		 }else if (productSource.equals(Const.JRXJ_RONG360)) {
			 //融360
			 product = productInfo.getRong360Product();
		 }else if (productSource.equals(Const.YXD_PRODUCT)) {
			 //游戏贷
			 product = productInfo.getYDXProduct();
		 }
		 for (Map<String, Object> m2 : product) {
	            //匹配成功是(今日现金 || 融360 || 游戏贷)的产品
	            if (String.valueOf(m2.get("productId")).equals(info.getProductName())) {
	            	Organization organizationS1 = null;
	       		    Organization organizationS2 = null;
	       		    Organization organizationS3 = null;
		       		for (Organization o : productInfo.getListOrganization()) {
		       			if (Const.CONSTANT_S1.equals(o.getName())) {
		       				organizationS1 = o;
		       			}else if (Const.CONSTANT_S2.equals(o.getName())) {
		       				organizationS2 = o;
		       			}else if (Const.CONSTANT_S3.equals(o.getName())) {
		       				organizationS3 = o;
		       			}
		       		}
	                info.setProductName(String.valueOf(m2.get("productName")));//设置产品的名称
	                info.setProductSource(productSource);//(今日现金 || 融360 || 游戏贷)
	                loger.info("单期产品的名称是==={}", info.getProductName());
	                //如果产品是单期的
	                 if (m.getOverdueDate() >= organizationS1.getMinDayNum() && m.getOverdueDate() <= organizationS1.getMaxDayNum()) {
	                    //2.逾期时间为[1,10]之间的的分配给s1组人员
	                    info.setOverdueDuration(Const.CONSTANT_S1);//催收组
	                    info.setOverdueStage(Const.CONSTANT_S1);//逾期阶段
	                }else if (m.getOverdueDate() >= organizationS2.getMinDayNum() && m.getOverdueDate() <= organizationS2.getMaxDayNum()) {
	                    info.setOverdueDuration(Const.CONSTANT_S2);//催收组
	                    info.setOverdueStage(Const.CONSTANT_S2);//逾期阶段
	                }else if(m.getOverdueDate() >= organizationS3.getMinDayNum()){
	                    info.setOverdueDuration(Const.CONSTANT_S3);//催收组
	                    info.setOverdueStage(Const.CONSTANT_S3);//逾期阶段
	                }else{
	                	loger.error("逾期天数分组数据异常======>{}" + m.getOverdueDate());
	                }
	            }
	        }

	}
	/**
	 * 多期产品(信用卡贷  + 消费分期)
	 * @param m
	 * @param info
	 * @param callLoanInfo
	 * @param productInfo
	 * @param productSource 产品来源
	 */
	public void multiphaseProduct(MidCallLoanInfo m,CallLoanInfo info,CallLoanInfo callLoanInfo, ProductInfo productInfo,String productSource){
		//循环迭代获取对应的产品
		 List<Map<String,Object>> product = new ArrayList<>();
		 if (productSource.equals(Const.XYKD_PRODUCT)) {
			 //信用卡贷
			 product = productInfo.getXRKDProduct();
		 }else if (productSource.equals(Const.XFFQ_PRODUCT)) {
			 //消费分期
			 product = productInfo.getXFFQProduct();
		 }else if (productSource.equals(Const.JYFQ_PRODUCT)) {
			 //教育分期
			 product = productInfo.getJYFQProduct();
		 }
		for (Map<String, Object> map : product){
            //匹配成功是信用卡贷的产品
            if (String.valueOf(map.get("productId")).equals(info.getProductName())) {
                info.setProductName(String.valueOf(map.get("productName")));//设置产品名称
                loger.info("多期的产品名称==={}", info.getProductName());
                info.setProductSource(productSource);//多期产品(信用卡贷  + 消费分期)
                //产品是信用卡贷
                if (callLoanInfo == null){
                    //如果是当月的逾期数据，则逾期分组为C-M1;
                    info.setOverdueDuration(Const.CONSTANT_M1);//催收组
                    info.setOverdueStage(Const.CONSTANT_M1);//逾期阶段

                }else if(DateUtil.getOneDay() == Const.ONE_DAY && callLoanInfo.getOverdueStage().equals(Const.CONSTANT_M1)  ){
                    //每月1号将上月C-M1组的数据分组为M1-M2；
                    info.setOverdueDuration(Const.CONSTANT_M2);//催收组
                    info.setOverdueStage(Const.CONSTANT_M2);//逾期阶段

                }else if(DateUtil.getOneDay() == Const.ONE_DAY && callLoanInfo.getOverdueStage().equals(Const.CONSTANT_M2)){
                    //每月1号将上月M1-M2组的数据分组为M2-M3；
                    info.setOverdueDuration(Const.CONSTANT_M3);//催收组
                    info.setOverdueStage(Const.CONSTANT_M3);//逾期阶段

                }else if(DateUtil.getOneDay() == Const.ONE_DAY && callLoanInfo.getOverdueStage().equals(Const.CONSTANT_M3)){
                    //每月1号将上月M2-M3组的数据分组为M3+
                    info.setOverdueDuration(Const.CONSTANT_M4);//催收组
                    info.setOverdueStage(Const.CONSTANT_M4);//逾期阶段
                }else{
                    info.setOverdueDuration(callLoanInfo.getOverdueDuration());//催收组
                    info.setOverdueStage(callLoanInfo.getOverdueStage());//逾期阶段
                }
            }
        }

	}


	/**
	 * 获取数据量大小
	 * @author dell、
	 *
	 */
	class PageResult{
		private int totalNumber;
		private int pageSize = 5000;
		private int beginIndex = 0;
		private int totalSize;
		public int getTotalNumber() {
			return totalNumber;
		}
		public void setTotalNumber(int totalNumber) {
			this.totalNumber = totalNumber;
		}
		public int getPageSize() {
			return pageSize;
		}
		public void setPageSize(int pageSize) {
			this.pageSize = pageSize;
		}
		public int getBeginIndex() {
			return beginIndex;
		}
		public void setBeginIndex(int beginIndex) {
			this.beginIndex = beginIndex;
		}
		public int getTotalSize() {
			return totalSize;
		}
		public void setTotalSize(int totalSize) {
			this.totalSize = totalSize;
		}


	}
    /**
	 * 逾期跑批Service
	 * 获取跑批传过来的所有数据
     * 判断数据是否在昨天已经被传过来,如果已经被传过来了,我需要去修改数据,没有被传过来的数据,我需要根据规则分配,插入到数据库去
     * 对于昨天所有没有结案的数据,我们需要去重新分配
	 */
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public void executeRunBatch(int count) throws Exception{
			   long beginTime = System.currentTimeMillis();
			   PageResult pageResult = new PageResult();
			   pageResult.setTotalNumber(midCallLoanInfoMapper.queryByCount());
		       loger.info("今日跑批更新的所有数据总量==>{}", pageResult.getTotalNumber());
		       pageResult.setTotalSize(pageResult.getTotalNumber() / pageResult.getPageSize());
		       List<MidCallLoanInfo> maps = new ArrayList<>();
		       TransferHistoryMode listInsert =new TransferHistoryMode();
		       TransferHistoryMode listUpdate =new TransferHistoryMode();
		       //创建存储产品信息的对象
		       ProductInfo productInfo = new ProductInfo();
		       //从标的库获取所有的产品名称
		       List<Map<String,Object>> allProduct = getProductName();
		       //分别注入到三个产品中
		       allotmentProduct(productInfo,allProduct);
		       //循环取数据
		       for (int i = 0; i <= pageResult.getTotalSize(); i++) {
		    	   maps = selectMidCallLoanInfo(pageResult.getBeginIndex(),pageResult.pageSize);
		    	   loger.info("今日跑批起始索引的大小是==>{}", pageResult.getBeginIndex());
		    	   pageResult.setBeginIndex(pageResult.getBeginIndex() + pageResult.pageSize);//下次获取的数据增加5000
		    	   int currentCount = mainPaoPi(count, maps, listInsert, listUpdate,productInfo);
		    	   count = currentCount;//跑完一次循环后count的值
		       }
		       long endTime = System.currentTimeMillis();
		       loger.info("跑批总花费时间==>{}",endTime - beginTime);

	}

	/**
	 * 跑批主逻辑代码
	 *
	 */
	public int mainPaoPi(int count,List<MidCallLoanInfo> maps,TransferHistoryMode listInsert,TransferHistoryMode listUpdate, ProductInfo productInfo) throws Exception{
			if (maps.size() <= 0) {
		    	   loger.info("中间表查询的数据为空!!!!!");
		    	   return 0;
		       }
		   for (MidCallLoanInfo m : maps) {
		       loger.info("==============打印出每一条数据================" + JSON.toJSON(m));
		           CallLoanInfo info = new CallLoanInfo();
		           info.setRepaymentId(m.getRepaymentId());//还款订单号

		            info.setBorrowDurationType(m.getBorrowDurationType());//借款期限类型
		            info.setBorrowName(m.getBorrowName());//借款名称
		            info.setBorrowNid(m.getBorrowNid());//借款编号
		            info.setCallLoanNid(Long.valueOf(DateUtil.getDays())*100000 + count + "");//催收编号
                    String contIdCard = m.getContIdCard();//获取到的身份证号
                    String provinceByIdCard = ProvinceUtil.getProvinceByIdCard(contIdCard);//根据身份证号获取户籍地
                    info.setProvince(provinceByIdCard);//客户户籍地
                    info.setContIdCard(contIdCard);//借款人身份证
		            info.setAccountId(m.getAccountId());//账户ID
		            //是否派发,默认为0
		            info.setOverdueAmount(m.getRemainAccount().add(m.getRecoverAmount()));//逾期总金额(累计未还金额 + 未还罚息)
		            //新增字段待测试=====================
		            info.setActualRecoverAmount(m.getActualRecoverAmount());//已还款金额
		            info.setNotReturnAmount(info.getOverdueAmount());//未还总金额
		            //新增字段待测试=====================
		            info.setOverdueCaptial(m.getOverdueCaptial());//逾期本金
		            info.setOverdueDate(m.getOverdueDate());//逾期天数
		            info.setOverdueFee(m.getRecoverAmount());//罚息(替换成未还罚息)
		            info.setOverdueInterest(m.getOverdueInterest());//逾期利息
		            info.setReceveFee(m.getReceveOverdueFee());//已还罚息
		            info.setOverdueManFee(m.getOverdueManFee());//逾期管理费
		            info.setOverdueSerFee(m.getOverdueSerFee());//逾期服务费
		            info.setReceveServiceFee(m.getReceveServiceFee());;//已还平台服务费
		            info.setPeriod(m.getPeriod());//逾期期数
		            info.setPeriodTotal(m.getPeriodTotal());//总期数
		            info.setTelephone(m.getTelephone());//电话号码
		            info.setUpdateTime(new Date());
		            info.setProductName(m.getProductId());//借款产品名称(借款产品的id)
		            this.singleProduct(m, info, productInfo, Const.JRXJ_PRODUCT);//今日现金产品
		            this.singleProduct(m, info, productInfo, Const.JRXJ_RONG360);//融360产品
		            this.singleProduct(m, info, productInfo, Const.YXD_PRODUCT);//游戏贷产品
		            this.singleProduct(m, info, productInfo, Const.YXD360_PRODUCT);//融360游戏贷产品
		            //查询本地数据库是否存在该产品
		            CallLoanInfo callLoanInfo = this.selectByRepaymentId(info.getRepaymentId());
		            multiphaseProduct(m, info, callLoanInfo, productInfo, Const.XYKD_PRODUCT);//信用卡贷产品
		            multiphaseProduct(m, info, callLoanInfo, productInfo, Const.XFFQ_PRODUCT);//消费分期产品
		            multiphaseProduct(m, info, callLoanInfo, productInfo, Const.JYFQ_PRODUCT);//教育分期
		            info.setRealName(m.getRealName());//真实姓名
		            info.setRecoverTime(m.getRecoverTime());//应还款时间
		            info.setRemainAccount(m.getRemainAccount());//累计未还金额(不含罚息)
		            //默认为待催收
		            info.setUserId(m.getUserId());//用户id
		            info.setCompensatoryStatus(m.getCompensatoryStatus());//设置现金贷的状态
		            //==============创建流转信息记录对象========================
		            TransferHistoryInfo transferHistoryInfo = new TransferHistoryInfo();
		            transferHistoryInfo.setCreateTime(new Date());//流转记录创建时间
		            transferHistoryInfo.setUpdateTime(new Date());//流转记录更新时间
		            transferHistoryInfo.setStartTime(new Date());//流转记录开始时间
		            transferHistoryInfo.setCurrentStatus(0);//流转记录待催收
		            transferHistoryInfo.setOperator(-1);//流转记录操作人
		            transferHistoryInfo.setCallLoanNid(info.getCallLoanNid());//流转记录催收编号
		            transferHistoryInfo.setToCallUid(-1);//当前催收员
		            transferHistoryInfo.setFromCallUid(-1);//之前催收员
		            transferHistoryInfo.setOverdueCaptial(info.getOverdueCaptial());//流转当期逾期本金
		            transferHistoryInfo.setOverdueInterest(info.getOverdueInterest());//流转当期逾期利息
		            transferHistoryInfo.setOverdueManFee(info.getOverdueManFee());//流转当期逾期管理费
		            transferHistoryInfo.setOverdueSerFee(info.getOverdueSerFee());//流转当期逾期服务费
		            transferHistoryInfo.setInOverdueFee(info.getOverdueFee());//流转当期逾期罚息
		            //==============创建流转信息记录对象=========================
		            transferHistoryInfo.setOverdueStage(info.getOverdueDuration());//流转记录逾期阶段
		            if (callLoanInfo == null) {
		                //如果没有数据插入数据
		                info.setCreateTime(new Date());//添加时间
		                listInsert.getInfo().add(info);
		                listInsert.getTransferHistoryInfo().add(transferHistoryInfo);

		                if (listInsert.getInfo().size() >= 1000) {
		             	   batchInsert(listInsert);
		                }
		                count = count + 1;
		            }else if(callLoanInfo.getStatus()==Const.CONSTANT_STRUTS2 || callLoanInfo.getStatus()== Const.CONSTANT_STRUTS4){
		                loger.info("该订单号==》{}在已结案或者委外结案中已存在，跑批不做处理",callLoanInfo.getRepaymentId());
		            }else{
		                //判断分组是否发生改变
		                //判断当前数据的状态,如果为委外催收中的,委外待催收,则状态不发生改变
		            	//判断当前数据的分组,如果分组为S2+阶段,则状态不发生改变
		            	//判断当前数据的分组,如果分组为S2阶段,则状态不发生改变
		                if (info.getOverdueDuration().equals(callLoanInfo.getOverdueDuration()) || callLoanInfo.getStatus() == Const.CONSTANT_STRUTS3
		             		    || callLoanInfo.getStatus() == Const.CONSTANT_STRUTS5
		             		    || Const.CONSTANT_S3.equals(info.getOverdueDuration())
		             		    || Const.CONSTANT_S2.equals(info.getOverdueDuration())) {
		                    info.setVersion(callLoanInfo.getVersion());//设置版本信息
		                    info.setCallUser(callLoanInfo.getCallUser());//催收员
		                    info.setStatus(callLoanInfo.getStatus());//催收状态
		                    info.setIsCall(callLoanInfo.getIsCall());//是否派发
		                }else{
		                    //分组发生改变(催收状态变为待催收/催收员变为null/是否派发变为否)
		                    info.setVersion(callLoanInfo.getVersion());//设置版本信息
		                    info.setStatus(0);//待催收
		                    info.setIsCall(0);//未派发
		                    //分组发生改变插入一条流转记录
		                    transferHistoryInfo.setCallLoanNid(callLoanInfo.getCallLoanNid());//获取当前分组改变的催收编号并修改流转记录的催收编号
		                    listUpdate.getTransferHistoryInfo().add(transferHistoryInfo);
		                    //分组发生改变插入一条流转记录
		                }
		                listUpdate.getInfo().add(info);
		                if (listUpdate.getInfo().size() >= 1000) {
		             	   batchUpdate(listUpdate);
		                }
		            }
		}
		//for循环结束后再次执行批量插入和批量更新(处理那些没有满足1000条的数据)
		batchInsert(listInsert);
		batchUpdate(listUpdate);
		return count;
	}

	/**
	 * 批量插入数据
	 *
	 * @param transferHistoryModeList
	 * @throws Exception
	 */
	private void batchInsert(TransferHistoryMode transferHistoryModeList) throws Exception{
		//批量插入主表
		dao.batchSave2("com.fh.mapper.loan.CallLoanInfoMapper.batchInsert", transferHistoryModeList.getInfo());
		//批量插入扭转记录表
		dao.batchSave2("com.fh.mapper.loan.TransferHistoryInfoMapper.insert", transferHistoryModeList.getTransferHistoryInfo());
		//清空集合
		List<CallLoanInfo> info = new ArrayList<>();
		transferHistoryModeList.setInfo(info);
		List<TransferHistoryInfo> transferHistoryInfo = new ArrayList<>();
		transferHistoryModeList.setTransferHistoryInfo(transferHistoryInfo);
	}
	/**
	 * 批量更新数据
	 * @param transferHistoryModeList
	 * @throws Exception
	 */
	private void batchUpdate(TransferHistoryMode transferHistoryModeList) throws Exception{
		//批量更新数据
		dao.batchUpdate("com.fh.mapper.loan.CallLoanInfoMapper.batchUpdate", transferHistoryModeList.getInfo());
		//批量插入扭转记录表
		dao.batchSave2("com.fh.mapper.loan.TransferHistoryInfoMapper.insert", transferHistoryModeList.getTransferHistoryInfo());
		//清空集合
		List<CallLoanInfo> info = new ArrayList<>();
		transferHistoryModeList.setInfo(info);
		List<TransferHistoryInfo> transferHistoryInfo = new ArrayList<>();
		transferHistoryModeList.setTransferHistoryInfo(transferHistoryInfo);

	}
	/**
	 * 将获取标的库的产品信息分配出来
	 * @param productInfo
	 *
	 * @param info
	 */
	private void allotmentProduct(ProductInfo productInfo, List<Map<String,Object>> info){
		for (Map<String, Object> m1 : info) {
			//获取所有的今日现金产品
			if ((m1.get("productSource") + "").equals(Const.JRXJ2_PRODUCT)  ||  (m1.get("productSource") + "").equals(Const.JRXJ_PRODUCT)) {
				productInfo.getJRXJProduct().add(m1);
			}
			//获取所有的融360产品
			if ((m1.get("productSource") + "").equals(Const.JRXJ_RONG360)) {
				productInfo.getRong360Product().add(m1);
			}
	    	//获取所有的信用卡贷的产品
			if ((m1.get("productSource") + "").equals(Const.XYKD_PRODUCT)) {
				productInfo.getXRKDProduct().add(m1);
			}
			//获取所有的消费分期的产品
			if ((m1.get("productSource") + "").equals(Const.XFFQ_PRODUCT)) {
				productInfo.getXFFQProduct().add(m1);
			}
			//获取所有的游戏贷的产品
			if ((m1.get("productSource") + "").equals(Const.YXD_PRODUCT)) {
				productInfo.getYDXProduct().add(m1);
			}
			//获取所有的教育分期的产品
			if ((m1.get("productSource") + "").equals(Const.JYFQ_PRODUCT)) {
				productInfo.getJYFQProduct().add(m1);
			}

		}
		//获取所有的分阶段天数
		try {
			productInfo.setListOrganization(organizationService.findAll());
		} catch (Exception e) {
			loger.error("获取分组Organization数据异常");
		}
		loger.info("获取今日现金所有产品的数量========{}" + productInfo.getJRXJProduct().size());
		loger.info("获取融360所有产品的数量========{}" + productInfo.getRong360Product().size());
		loger.info("获取信用卡贷所有产品的数量========{}" + productInfo.getXRKDProduct().size());
		loger.info("获取消费分期所有产品的数量========{}" + productInfo.getXFFQProduct().size());
		loger.info("获取游戏贷所有产品的数量========{}" + productInfo.getYDXProduct().size());
		loger.info("获取教育分期所有产品的数量========{}" + productInfo.getJYFQProduct().size());
	}

	//内部类
	class TransferHistoryMode{
		private List<CallLoanInfo> info = new ArrayList<>();
		private List<TransferHistoryInfo> transferHistoryInfo = new ArrayList<>();

		public List<CallLoanInfo> getInfo() {
			return info;
		}
		public void setInfo(List<CallLoanInfo> info) {
			this.info = info;
		}
		public List<TransferHistoryInfo> getTransferHistoryInfo() {
			return transferHistoryInfo;
		}
		public void setTransferHistoryInfo(List<TransferHistoryInfo> transferHistoryInfo) {
			this.transferHistoryInfo = transferHistoryInfo;
		}
	}
	/**
	 * 存储不同产品的集合
	 *
	 */
	class ProductInfo{
		//单期产品分组天数
		List<Organization> listOrganization = new ArrayList<>();
		//今日现金
		private List<Map<String,Object>> JRXJProduct = new ArrayList<>();
		//信用卡贷
		private List<Map<String,Object>> XRKDProduct = new ArrayList<>();
		//融360
		private List<Map<String,Object>> Rong360Product = new ArrayList<>();
		//消费分期
		private List<Map<String,Object>> XFFQProduct = new ArrayList<>();
		//游戏贷
		private List<Map<String,Object>> YDXProduct = new ArrayList<>();
		//教育分期
		private List<Map<String,Object>> JYFQProduct = new ArrayList<>();

		public List<Map<String, Object>> getJRXJProduct() {
			return JRXJProduct;
		}
		public void setJRXJProduct(List<Map<String, Object>> jRXJProduct) {
			JRXJProduct = jRXJProduct;
		}
		public List<Map<String, Object>> getXRKDProduct() {
			return XRKDProduct;
		}
		public void setXRKDProduct(List<Map<String, Object>> xRKDProduct) {
			XRKDProduct = xRKDProduct;
		}
		public List<Map<String, Object>> getRong360Product() {
			return Rong360Product;
		}
		public void setRong360Product(List<Map<String, Object>> rong360Product) {
			Rong360Product = rong360Product;
		}
		public List<Map<String, Object>> getXFFQProduct() {
			return XFFQProduct;
		}
		public void setXFFQProduct(List<Map<String, Object>> xFFQProduct) {
			XFFQProduct = xFFQProduct;
		}
		public List<Map<String, Object>> getYDXProduct() {
			return YDXProduct;
		}
		public void setYDXProduct(List<Map<String, Object>> yDXProduct) {
			YDXProduct = yDXProduct;
		}
		public List<Organization> getListOrganization() {
			return listOrganization;
		}
		public void setListOrganization(List<Organization> listOrganization) {
			this.listOrganization = listOrganization;
		}
		public List<Map<String, Object>> getJYFQProduct() {
			return JYFQProduct;
		}
		public void setJYFQProduct(List<Map<String, Object>> jYFQProduct) {
			JYFQProduct = jYFQProduct;
		}


	}
	/**
	 * 插入跑批成功失败flag
	 */
	@Transactional
	public void insertFlag(String flag) {
		try {
			RunBatchFlag info = new RunBatchFlag();
			//设置跑批相关的信息
			info.setCreateTime(new Date());
			info.setRunTime(Integer.valueOf(DateUtil.getDays()));
			info.setUpdateTime(new Date());
			info.setFalge(flag);
			info.setJobName("call_loan_info");
			runBatchFlagMapper.insert(info);
		} catch (Exception e) {
			loger.error("插入跑批监控信息失败", e);

		}
	}
}
